package com.itheima.reggie.controller;

import com.itheima.reggie.common.ResultInfo;
import com.itheima.reggie.domain.Category;
import com.itheima.reggie.domain.Dish;
import com.itheima.reggie.service.CategoryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

@RestController
@Slf4j
public class CategoryController {
    @Autowired
    private CategoryService categoryService;

    //查询全部
    @GetMapping("/category/findAll")
    private ResultInfo findAll(){
        List<Category> categoryList = categoryService.findAll();
        return ResultInfo.success(categoryList);
    }

    //新增方法
    @PostMapping("/category")
    public ResultInfo save(@RequestBody Category category){
        categoryService.save(category);
        return ResultInfo.success(null);
    }

    //更新
    @PutMapping("/category")
    public ResultInfo update(@RequestBody Category category){
        categoryService.update(category);
        return ResultInfo.success(null);
    }

    //根据id删除
    @DeleteMapping("/category")
    public ResultInfo deleteById(long id){
      log.info("1",id);
        //1.调用方法
        ResultInfo resultInfo = categoryService.deleteById(id);

        //2.返回结果
        return resultInfo;

    }
    //根据type查询
    @GetMapping("/category/list")
    public ResultInfo findList(Integer type){
        List<Category> categoryList = categoryService.findList(type);
        return ResultInfo.success(categoryList);
    }


}
